<?
 require_once("functions.php");

function addInventory($new_address_array)
{
	$database = getDB();
	
	$new_address_array = arrayEscape($new_address_array, $database);
	
	$statement = "INSERT INTO Inventory (change_units, Sku_id) VALUES ('$new_address_array[change_units]', '$new_address_array[Sku_id]')";

	$results = $database->query($statement);
	
	$error = $database->error;

	$database->close();
	
	return $error == "" ? true : array('SQL Error'=> $error);
}

function getInventory($sku)
{
	$database = getDB();
	
	$statement = "SELECT SUM(change_units) AS stock FROM Inventory WHERE Sku_id = '$sku'";

	$results = $database->query($statement);
	
	$stock = $results->fetch_assoc();
	
	return $stock['stock'];
}

function getProducts()
{
	$database = getDB();
	
	$statement = "SELECT Sku.id AS Sku, product_name, name FROM Sku LEFT JOIN Vendor ON Vendor_id = Vendor.id ORDER BY Sku.id ASC";

	$results = $database->query($statement);
	
	return $results;
}
?>